//
//  ViewController.m
//  new
//
//  Created by  Mac on 2017/8/30.
//  Copyright © 2017年  Mac. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *backView;
@property (weak, nonatomic) IBOutlet UITextField *tf;




@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.backView.backgroundColor = [UIColor redColor];
    
    
    
}
- (IBAction)btnclick:(UIButton *)sender {
    
    
    for(UIView *view in [_backView subviews])
    {
        [view removeFromSuperview];
    }
    
    
    float width = CGRectGetWidth(self.backView.bounds);
    
    int  count = [_tf.text intValue];
    
    for (int i = 1 ; i < count + 1; i ++) {
        
        
        UIView * view = [[UIView alloc]initWithFrame:CGRectMake(((2*i-1) * width)/(2 * count) - 25, 0, 50, 50)];
        view.layer.cornerRadius = 25;
        view.backgroundColor = [UIColor whiteColor];
        [_backView addSubview:view];
        
    }
    
}



//更难的
- (IBAction)btnclickForExcellent:(UIButton *)sender {
    
    for(UIView *view in [_backView subviews])
    {
        [view removeFromSuperview];
    }
    
    
    
    
    float width =  CGRectGetWidth(self.backView.bounds);
    int count = [_tf.text intValue];
    
    int p[count];
    for (int i = 0 ; i < count; i ++) {
        p[i] = -(count - 1)/2 + i;
    }
    
    int d[count];
    for (int i = 0; i < count; i ++) {
        if (-count/2 + i >= 0) {
            d[i] =  -count/2 + i + 1;
        }else
        {
            d[i] = -count/2 + i;
        }
    }
    

    for (int i = 1; i < count + 1; i ++) {
        
        if(count%2 == 0)
        {
            
            if(d[i - 1] > 0)
            {
                UIView * view = [[UIView alloc]initWithFrame:CGRectMake(width/2 + 5/2 + (d[i - 1]  - 1) * (50 + 5) , 0, 50, 50)];
                view.layer.cornerRadius = 25;
                view.backgroundColor = [UIColor whiteColor];
                [_backView addSubview:view];
            }
            else
            {
                UIView * view = [[UIView alloc]initWithFrame:CGRectMake(width/2 - 5/2 + d[i - 1] * 50 + (d[i -1] + 1) * 5, 0, 50, 50)];
                view.layer.cornerRadius = 25;
                view.backgroundColor = [UIColor whiteColor];
                [_backView addSubview:view];
                
            }
            
        }
        else
        {
            
            
            UIView * view = [[UIView alloc]initWithFrame:CGRectMake(width/2 - p[i - 1] * (50 + 5) - 50 / 2, 0, 50, 50)];
            view.layer.cornerRadius = 25;
            view.backgroundColor = [UIColor whiteColor];
            [_backView addSubview:view];
            
            
        }
    }
    
    
    
    
    
}

//c语言对称数组
- (IBAction)getArrayForCLanuage:(UIButton *)sender {
    int  count = [_tf.text intValue];
    int  e[count];
//    int  p[count];
//    int  d[count];
    
    if (count%2 ==0)
    {
        for (int i = 0; i < count; i ++) {
            if (-count/2 + i >= 0) {
                e[i] =  -count/2 + i + 1;
            }else
            {
                e[i] = -count/2 + i;
            }
        }
    }
    else
    {
        for (int i = 0 ; i < count; i ++) {
            e[i] = -(count - 1)/2 + i;
        }
        
    }
    
    for (int i = 0; i < count; i ++) {
        printf("%d ", e[i]);
    }
    
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
